<template>
  <div>
    <city-headers></city-headers>
    <city-search :cities="cities"></city-search>
    <city-list :cities="cities" :hot="hotCities" :letter="letter"></city-list>
    <city-alphabet :cities="cities" @change="handleLetterChange" ></city-alphabet>
  </div>
</template>

<script>
import CityHeaders from './components/Headers.vue'
import CitySearch from './components/Search.vue'
import CityList from './components/List.vue'
import CityAlphabet from './components/Alphabet.vue'
import axios from 'axios'
export default {
  components: {CityHeaders,CitySearch,CityList,CityAlphabet},
  name:'City',
  data (){
    return {
      cities:{},
      hotCities:[],
      letter:''
    }
  },
  methods:{
    getCityTnfo (){
      axios.get('/api/city.json')
        .then(this.getCityInfoSucc)
    },
    getCityInfoSucc (res){
      res = res.data
      if(res.ret&&res.data){
        const data = res.data
        this.cities=data.cities
        this.hotCities=data.hotCities
      }
    },
    handleLetterChange (letter){
      this.letter = letter
    }

  },
  mounted (){
    this.getCityTnfo()
  }
}
</script>

<style lang="stylus" scoped>

</style>
